﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CSM_SQL.BLL;

namespace CommunitySuperMarketManager.Controllers
{
    
    public class LoginController : Controller
    {
        // GET: Login
        public ActionResult Login()
        {
            return View();
        }

        public void Valid()
        {
            var name = Request.Params["name"];
            var password = MD5BLL.EncryptString(Request.Params["password"]);
            EmpBLL eb = new EmpBLL();
            var emp = eb.All();
            foreach(var e in emp)
            {
                if(e.Name == name)
                {
                    if(e.Password == password)
                    {
                        Session["CurrUser"] = e;
                        HttpContext.Response.Write(0);
                        HttpContext.Response.End();
                        break;
                    }
                    HttpContext.Response.Write(1);
                    HttpContext.Response.End();
                    break;
                }
            }
            HttpContext.Response.Write(2);
            HttpContext.Response.End();
        
        }
    }
}